define(function(){
	// checkbox
	/*
	var scrollBar=new ScrollBar({
		scrollWindow:'.chatRecord',//容器dom
		scrollContent:'.recordList',//内容dom
		//scrollStart:'left,top',//滚动初始化朝向
		//scrollStart:'right,bottom',
		scrollStart:'left,bottom',
		//mousewheel:false,//是否允许鼠标滚轮事件 默认true
		//hideScrollBar:true,//是否隐藏滚动条 默认false
		//scrollTime:100, //平滑滚动时长 默认0
		byTransform:true, //是否启用css3模式 默认false
		touchDrag:true, //是否启动手机端touch模式 默认false
		autoHide:true, //是否自动隐藏滚动条只在滚动时显示 默认false
		callback:{
			scrollTopEnd:function(){
				console.log('i\'m scroll to top');
			},
			scrollBottomEnd:function(){
				console.log('i\'m scroll to bottom');
			},
			scrollLeftEnd:function(){
				console.log('i\'m scroll to left');
			},
			scrollRightEnd:function(){
				console.log('i\'m scroll to right');
			}
		}
	})
	*/
	var ScrollBar=function (config){
		var scrollBar=this;

		scrollBar.scrollByTransform=config.byTransform || false;

		if(config.scrollTime==undefined){
			config.scrollTime=0;
		}
		scrollBar.scrollTime=config.scrollTime;

		if(config.mousewheel==undefined){
			config.mousewheel=true;
		}
		scrollBar.mousewheel=config.mousewheel;

		if(config.touchscroll==undefined){
			config.touchscroll=false;
		}
		scrollBar.touchscroll=config.touchscroll;

		if(config.hideScrollBar==undefined){
			config.hideScrollBar=false;
		}
		scrollBar.hideScrollBar=config.hideScrollBar;

		if(config.touchDrag==undefined){
			config.touchDrag=false;
		}
		scrollBar.touchDrag=config.touchDrag;

		if(config.autoHide==undefined){
			config.autoHide=false;
		}
		scrollBar.autoHide=config.autoHide;

		scrollBar.callback=config.callback || {}

		scrollBar.callback.scrollTopEnd=scrollBar.callback.scrollTopEnd ||function(){};
		scrollBar.callback.scrollBottomEnd=scrollBar.callback.scrollBottomEnd ||function(){};
		scrollBar.callback.scrollLeftEnd=scrollBar.callback.scrollLeftEnd ||function(){};
		scrollBar.callback.scrollRightEnd=scrollBar.callback.scrollRightEnd ||function(){};


		scrollBar.$scrollWindow=config.scrollWindow;
		if(typeof scrollBar.$scrollWindow=='string'){
			scrollBar.$scrollWindow=$(scrollBar.$scrollWindow);
		}

		scrollBar.$scrollContent=config.scrollContent;
		if(typeof scrollBar.$scrollContent=='string'){
			scrollBar.$scrollContent=$(scrollBar.$scrollContent);
		}


		scrollBar.scrollStart={};
		$.each((config.scrollStart||'').split(','), function(i,startName) {
			switch(startName){
				case 'left':
					scrollBar.scrollStart.x='left';
					break;
				case 'right':
					scrollBar.scrollStart.x='right';
					break;
				case 'top':
					scrollBar.scrollStart.y='top';
					break;
				case 'bottom':
					scrollBar.scrollStart.y='bottom';
					break;
			}
		});


		scrollBar.$scrollBarX=$('<div class="scrollBar horizontal"></div>');
		scrollBar.$scrollBtnX=$('<input type="button" class="scrollBtn" />').appendTo(scrollBar.$scrollBarX);
		scrollBar.needScroll={
			x:false,
			y:false
		}

		scrollBar.$scrollBarY=$('<div class="scrollBar vertical"></div>');
		scrollBar.$scrollBtnY=$('<input type="button" class="scrollBtn" />').appendTo(scrollBar.$scrollBarY);


		switch(scrollBar.scrollStart.x){
			case 'left':
				scrollBar.$scrollContent.css({
					left:0
				});
				scrollBar.$scrollBtnX.css({
					left:0,
					right:'auto'
				});
				break;
			case 'right':
				scrollBar.$scrollContent.css({
					right:0
				});
				scrollBar.$scrollBtnX.css({
					left:'auto',
					right:0
				});
				break;
		}
		switch(scrollBar.scrollStart.y){
			case 'top':
				scrollBar.$scrollContent.css({
					top:0
				});
				scrollBar.$scrollBtnY.css({
					top:0,
					bottom:'auto'
				});
				break;
			case 'bottom':
				scrollBar.$scrollContent.css({
					bottom:0
				});
				scrollBar.$scrollBtnY.css({
					top:'auto',
					bottom:0
				});
				break;
		}
		if(config.hideScrollBar){
			scrollBar.$scrollBarX.css({
				'visibility':'hidden'
			})
			scrollBar.$scrollBarY.css({
				'visibility':'hidden'
			})
		}
		if(scrollBar.autoHide){
			scrollBar.$scrollBarX.css({
				'opacity':'0'
			})
			scrollBar.$scrollBarY.css({
				'opacity':'0'
			})
		}
		scrollBar.scrollDistance={
			left:0,
			top:0,
			right:0,
			bottom:0
		};


		var domSize={
			scrollWindow:{
				width:0,
				height:0
			},
			scrollContent:{
				width:0,
				height:0
			},
			scrollBar:{
				xWidth:0,
				yHeight:0
			},
			scrollScale:{
				x:0,
				y:0
			},
			scrollRange:{
				x:{
					min:0,
					max:0
				},
				y:{
					min:0,
					max:0
				}
			},
			resize:function(){
				domSize.scrollWindow.width=scrollBar.$scrollWindow.width();
				domSize.scrollWindow.height=scrollBar.$scrollWindow.height();
				domSize.scrollContent.width=scrollBar.$scrollContent.outerWidth();
				domSize.scrollContent.height=scrollBar.$scrollContent.outerHeight();
				domSize.scrollBar.xWidth=scrollBar.$scrollBarX.width();
				domSize.scrollBar.yHeight=scrollBar.$scrollBarY.height();

				domSize.scrollScale.width=domSize.scrollWindow.width/domSize.scrollContent.width;
				domSize.scrollScale.height=domSize.scrollWindow.height/domSize.scrollContent.height;


				switch(scrollBar.scrollStart.x){
					case 'left':
						if(scrollBar.scrollByTransform){
							domSize.scrollRange.x={
								min:-(domSize.scrollContent.width-domSize.scrollWindow.width),
								max:0
							}
						}else{
							domSize.scrollRange.x={
								min:-(domSize.scrollContent.width-domSize.scrollWindow.width),
								max:0
							}
						}
						break;
					case 'right':
						if(scrollBar.scrollByTransform){
							domSize.scrollRange.x={
								min:0,
								max:domSize.scrollContent.width-domSize.scrollWindow.width
							}
							if(domSize.scrollRange.x.max<0){
								domSize.scrollRange.x.max=0;
							}
						}else{
							domSize.scrollRange.x={
								min:-(domSize.scrollContent.width-domSize.scrollWindow.width),
								max:0
							}
						}
						break;
				}
				switch(scrollBar.scrollStart.y){
					case 'top':
						if(scrollBar.scrollByTransform){
							domSize.scrollRange.y={
								min:-(domSize.scrollContent.height-domSize.scrollWindow.height),
								max:0
							}
						}else{
							domSize.scrollRange.y={
								min:-(domSize.scrollContent.height-domSize.scrollWindow.height),
								max:0
							}
						}
						break;
					case 'bottom':
						if(scrollBar.scrollByTransform){
							domSize.scrollRange.y={
								min:0,
								max:domSize.scrollContent.height-domSize.scrollWindow.height
							}
							if(domSize.scrollRange.y.max<0){
								domSize.scrollRange.y.max=0;
							}
						}else{
							domSize.scrollRange.y={
								min:-(domSize.scrollContent.height-domSize.scrollWindow.height),
								max:0
							}
						}
						break;
				}

			}
		}
		scrollBar.$scrollWindow.append(scrollBar.$scrollBarX,scrollBar.$scrollBarY);
		domSize.resize();

		scrollBar.show=function(){
			if(domSize.scrollScale.width<1){
				scrollBar.$scrollBtnX.width(domSize.scrollBar.xWidth*domSize.scrollScale.width);
				scrollBar.needScroll.x=true;
				scrollBar.$scrollBarX.show();
			}else{
				scrollBar.needScroll.x=false;
				scrollBar.$scrollBarX.hide();
			}

			if(domSize.scrollScale.height<1){
				scrollBar.$scrollBtnY.height(domSize.scrollBar.yHeight*domSize.scrollScale.height);
				scrollBar.needScroll.y=true;
				scrollBar.$scrollBarY.show();
			}else{
				scrollBar.needScroll.y=false;
				scrollBar.$scrollBarY.hide();
			}
		}
		scrollBar.resize=function(){
			domSize.resize();
			scrollBar.show();
			scrollBar.contentScroll();
			scrollBar.scrollBtnXMove();
			scrollBar.scrollBtnYMove();
		}
		scrollBar.reScroll=function(){
			scrollBar.scrollDistance={
				left:0,
				top:0,
				right:0,
				bottom:0
			};
			var scrollTime=scrollBar.scrollTime;
			if(scrollTime>0){
				scrollBar.scrollTime=0;
				scrollBar.setTransitionTime();
			}
			scrollBar.resize();
			setTimeout(function(){
				if(scrollTime>0){
					scrollBar.scrollTime=scrollTime;
					scrollBar.setTransitionTime();
				}
			},0)
		}
		$(window).on('resize',function(){
			scrollBar.resize();
		})


		scrollBar.contentScroll=function(){
			var scrollCssObj={};
			var scrollAnimateObj={};
			var scrollEndEvent={
				x:{
					min:false,
					max:false
				},
				y:{
					min:false,
					max:false
				}
			};

			switch(scrollBar.scrollStart.x){
				case 'left':
					if(scrollBar.scrollDistance.left<domSize.scrollRange.x.min){
						scrollBar.scrollDistance.left=domSize.scrollRange.x.min;
						scrollEndEvent.x.min=true;
					}
					if(scrollBar.scrollDistance.left>domSize.scrollRange.x.max){
						scrollBar.scrollDistance.left=domSize.scrollRange.x.max;
						scrollEndEvent.x.max=true;
					}
					if(scrollBar.scrollByTransform){
						scrollCssObj.translateX=scrollBar.scrollDistance.left;
						scrollEndEvent.x.min && scrollBar.needScroll.x && scrollBar.callback.scrollRightEnd();
						scrollEndEvent.x.max && scrollBar.needScroll.x && scrollBar.callback.scrollLeftEnd();
					}else{
						scrollAnimateObj.marginLeft=scrollBar.scrollDistance.left;
						scrollEndEvent.x.min && scrollBar.needScroll.x && scrollBar.callback.scrollRightEnd();
						scrollEndEvent.x.max && scrollBar.needScroll.x && scrollBar.callback.scrollLeftEnd();
					}
					break;
				case 'right':
					if(scrollBar.scrollDistance.right<domSize.scrollRange.x.min){
						scrollBar.scrollDistance.right=domSize.scrollRange.x.min;
						scrollEndEvent.x.min=true;
					}
					if(scrollBar.scrollDistance.right>domSize.scrollRange.x.max){
						scrollBar.scrollDistance.right=domSize.scrollRange.x.max;
						scrollEndEvent.x.max=true;
					}
					if(scrollBar.scrollByTransform){
						scrollCssObj.translateX=scrollBar.scrollDistance.right;
						scrollEndEvent.x.min && scrollBar.needScroll.x && scrollBar.callback.scrollRightEnd();
						scrollEndEvent.x.max && scrollBar.needScroll.x && scrollBar.callback.scrollLeftEnd();
					}else{
						scrollAnimateObj.marginRight=scrollBar.scrollDistance.right;
						scrollEndEvent.x.max && scrollBar.needScroll.x && scrollBar.callback.scrollRightEnd();
						scrollEndEvent.x.min && scrollBar.needScroll.x && scrollBar.callback.scrollLeftEnd();
					}
					break;
			}
			switch(scrollBar.scrollStart.y){
				case 'top':
					if(scrollBar.scrollDistance.top<domSize.scrollRange.y.min){
						scrollBar.scrollDistance.top=domSize.scrollRange.y.min;
						scrollEndEvent.y.min=true;
					}
					if(scrollBar.scrollDistance.top>domSize.scrollRange.y.max){
						scrollBar.scrollDistance.top=domSize.scrollRange.y.max;
						scrollEndEvent.y.max=true;
					}
					if(scrollBar.scrollByTransform){
						scrollCssObj.translateY=scrollBar.scrollDistance.top;
						scrollEndEvent.y.min && scrollBar.needScroll.y && scrollBar.callback.scrollBottomEnd();
						scrollEndEvent.y.max && scrollBar.needScroll.y && scrollBar.callback.scrollTopEnd();
					}else{
						scrollAnimateObj.marginTop=scrollBar.scrollDistance.top;
						scrollEndEvent.y.min && scrollBar.needScroll.y && scrollBar.callback.scrollBottomEnd();
						scrollEndEvent.y.max && scrollBar.needScroll.y && scrollBar.callback.scrollTopEnd();
					}
					break;
				case 'bottom':
					if(scrollBar.scrollDistance.bottom<domSize.scrollRange.y.min){
						scrollBar.scrollDistance.bottom=domSize.scrollRange.y.min;
						scrollEndEvent.y.min=true;
					}
					if(scrollBar.scrollDistance.bottom>domSize.scrollRange.y.max){
						scrollBar.scrollDistance.bottom=domSize.scrollRange.y.max;
						scrollEndEvent.y.max=true;
					}
					if(scrollBar.scrollByTransform){
						scrollCssObj.translateY=scrollBar.scrollDistance.bottom;
						scrollEndEvent.y.min && scrollBar.needScroll.y && scrollBar.callback.scrollBottomEnd();
						scrollEndEvent.y.max && scrollBar.needScroll.y && scrollBar.callback.scrollTopEnd();
					}else{
						scrollAnimateObj.marginBottom=scrollBar.scrollDistance.bottom;
						scrollEndEvent.y.max && scrollBar.needScroll.y && scrollBar.callback.scrollBottomEnd();
						scrollEndEvent.y.min && scrollBar.needScroll.y && scrollBar.callback.scrollTopEnd();
					}
					break;
			}
			if(scrollBar.scrollByTransform){
				scrollBar.$scrollContent.css({
					'-webkit-transform':'translate('+scrollCssObj.translateX+'px,'+scrollCssObj.translateY+'px)'
				})
			}else{
				scrollBar.$scrollContent.stop(false,false).animate(scrollAnimateObj,scrollBar.scrollTime,'linear');
			}
		}
		scrollBar.contentScrollX=function(distance,byScrollBar){
			switch(scrollBar.scrollStart.x){
				case 'left':
					if(byScrollBar){
						distance=distance*domSize.scrollContent.width/domSize.scrollBar.xWidth;
					}
					if(scrollBar.scrollByTransform){
						scrollBar.scrollDistance.left+=distance;
					}else{
						scrollBar.scrollDistance.left+=distance;
					}
					break;
				case 'right':
					if(byScrollBar){
						distance=distance*domSize.scrollContent.width/domSize.scrollBar.xWidth;
					}
					if(scrollBar.scrollByTransform){
						scrollBar.scrollDistance.right-=distance;
					}else{
						scrollBar.scrollDistance.right+=distance;
					}
					break;
			}
			scrollBar.contentScroll();
			scrollBar.scrollBtnXMove();
		}
		scrollBar.scrollBtnXMove=function(){
			if(scrollBar.autoHide){
				scrollBar.$scrollBarX.css({
					'opacity':'1'
				});
			}
			switch(scrollBar.scrollStart.x){
				case 'left':
					distance=domSize.scrollBar.xWidth*scrollBar.scrollDistance.left/domSize.scrollContent.width;
					if(scrollBar.scrollByTransform){
						scrollBar.$scrollBtnX.css({
							'-webkit-transform': 'translateX('+-distance+'px)'
						});
					}else{
						scrollBar.$scrollBtnX.stop(false,false).animate({
							marginLeft:-distance
						},scrollBar.scrollTime,'linear');
					}
					break;
				case 'right':
					distance=domSize.scrollBar.xWidth*scrollBar.scrollDistance.right/domSize.scrollContent.width;
					if(scrollBar.scrollByTransform){
						scrollBar.$scrollBtnX.css({
							'-webkit-transform': 'translateX('+-distance+'px)'
						});
					}else{
						scrollBar.$scrollBtnX.stop(false,false).animate({
							marginRight:-distance
						},scrollBar.scrollTime,'linear');
					}
					break;
			}
			if(scrollBar.autoHide){
				scrollBar.$scrollBarX.stop(false,false).animate({
					'opacity':'0'
				},300);
			}
		}
		scrollBar.scrollXDrag={
			isStart:false,
			start:function(isStart){
				if(isStart){
					scrollBar.scrollXDrag.isStart=true;
					scrollBar.$scrollWindow.addClass('user-select-none');
				}else{
					scrollBar.scrollXDrag.isStart=false;
					scrollBar.$scrollWindow.removeClass('user-select-none');
				}
			},
			postion:{
				x:0
			}
		}
		scrollBar.$scrollBtnX.on('mousedown',function(e){
			//console.log("start dragX");
			scrollBar.scrollXDrag.start(true);
			scrollBar.scrollXDrag.postion.x=e.pageX;
		})
		$(window).on('mousemove',function(e){
			if(scrollBar.scrollXDrag.isStart){
				//console.log("draging");
				var moveLength;
				switch(scrollBar.scrollStart.x){
					case 'left':
						moveLength=scrollBar.scrollXDrag.postion.x-e.pageX;
						break;
					case 'right':
						moveLength=e.pageX-scrollBar.scrollXDrag.postion.x;
						break;
				}

				scrollBar.contentScrollX(moveLength,true);
				scrollBar.scrollXDrag.postion.x=e.pageX;
			}
		})
		$(window).on('mouseup',function(e){
			scrollBar.scrollXDrag.start(false);
		})


		scrollBar.contentScrollY=function(distance,byScrollBar){
			switch(scrollBar.scrollStart.y){
				case 'top':
					if(byScrollBar){
						distance=distance*domSize.scrollContent.height/domSize.scrollBar.yHeight;
					}
					if(scrollBar.scrollByTransform){
						scrollBar.scrollDistance.top+=distance;
					}else{
						scrollBar.scrollDistance.top+=distance;
					}
					break;
				case 'bottom':
					if(byScrollBar){
						distance=distance*domSize.scrollContent.height/domSize.scrollBar.yHeight;
					}
					if(scrollBar.scrollByTransform){
						scrollBar.scrollDistance.bottom-=distance;
					}else{
						scrollBar.scrollDistance.bottom+=distance;
					}
					break;
			}
			scrollBar.contentScroll();
			scrollBar.scrollBtnYMove();
		}

		scrollBar.scrollBtnYMove=function(){
			if(scrollBar.autoHide){
				scrollBar.$scrollBarY.css({
					'opacity':'1'
				});
			}
			switch(scrollBar.scrollStart.y){
				case 'top':
					distance=domSize.scrollBar.yHeight*scrollBar.scrollDistance.top/domSize.scrollContent.height;
					if(scrollBar.scrollByTransform){
						scrollBar.$scrollBtnY.css({
							'-webkit-transform': 'translateY('+-distance+'px)'
						});
					}else{
						scrollBar.$scrollBtnY.stop(false,false).animate({
							marginTop:-distance
						},scrollBar.scrollTime,'linear');
					}
					break;
				case 'bottom':
					distance=domSize.scrollBar.yHeight*scrollBar.scrollDistance.bottom/domSize.scrollContent.height;
					if(scrollBar.scrollByTransform){
						scrollBar.$scrollBtnY.css({
							'-webkit-transform': 'translateY('+-distance+'px)'
						});
					}else{
						scrollBar.$scrollBtnY.stop(false,false).animate({
							marginBottom:-distance
						},scrollBar.scrollTime,'linear');
					}
					break;
			}
			if(scrollBar.autoHide){
				scrollBar.$scrollBarY.stop(false,false).animate({
					'opacity':'0'
				},300);
			}
		}

		scrollBar.show();


		scrollBar.setTransitionTime=function(){
			if(scrollBar.scrollByTransform && scrollBar.scrollTime>0){
				scrollBar.$scrollContent.css({
					'-webkit-transition':scrollBar.scrollTime+'ms linear'
				});
				scrollBar.$scrollBtnX.css({
					'-webkit-transition':scrollBar.scrollTime+'ms linear'
				});
				scrollBar.$scrollBtnY.css({
					'-webkit-transition':scrollBar.scrollTime+'ms linear'
				});
			}else{
				scrollBar.$scrollContent.css({
					'-webkit-transition':''
				});
				scrollBar.$scrollBtnX.css({
					'-webkit-transition':''
				});
				scrollBar.$scrollBtnY.css({
					'-webkit-transition':''
				});
			}
		}
		scrollBar.setTransitionTime();




		scrollBar.scrollYDrag={
			isStart:false,
			start:function(isStart){
				if(isStart){
					scrollBar.scrollYDrag.isStart=true;
					scrollBar.$scrollWindow.addClass('user-select-none');
				}else{
					scrollBar.scrollYDrag.isStart=false;
					scrollBar.$scrollWindow.removeClass('user-select-none');
				}
			},
			postion:{
				y:0
			}
		}

		scrollBar.$scrollBtnY.on('mousedown',function(e){
			//console.log("start drag");
			scrollBar.scrollYDrag.start(true);
			scrollBar.scrollYDrag.postion.y=e.pageY;
		});
		$(window).on('mousemove',function(e){
			if(scrollBar.scrollYDrag.isStart){
				//console.log("draging");
				var moveLength;
				switch(scrollBar.scrollStart.y){
					case 'top':
						moveLength=scrollBar.scrollYDrag.postion.y-e.pageY;
						break;
					case 'bottom':
						moveLength=e.pageY-scrollBar.scrollYDrag.postion.y;
						break;
				}

				scrollBar.contentScrollY(moveLength,true);
				scrollBar.scrollYDrag.postion.y=e.pageY;
			}
		});
		$(window).on('mouseup',function(e){
			scrollBar.scrollYDrag.start(false);
		});




		scrollBar.$scrollWindow.on('mousewheel',function(e,delta){
			e.preventDefault();
			if(scrollBar.needScroll.y && scrollBar.mousewheel){
				if(delta>0){
					//console.log("scrollUp");
					switch(scrollBar.scrollStart.y){
						case 'top':
							scrollBar.contentScrollY(50)
							break;
						case 'bottom':
							scrollBar.contentScrollY(-50)
							break;
					}
				}
				if(delta<0){
					//console.log("scrollDown");
					switch(scrollBar.scrollStart.y){
						case 'top':
							scrollBar.contentScrollY(-50)
							break;
						case 'bottom':
							scrollBar.contentScrollY(50)
							break;
					}
				}
			}
		});
		scrollBar.$scrollBarX.on('mousewheel',function(e,delta){
			e.preventDefault();
			e.stopPropagation();
			if(scrollBar.needScroll.x && scrollBar.mousewheel){
				if(delta>0){
					//console.log("scrollUp");
					switch(scrollBar.scrollStart.x){
						case 'left':
							scrollBar.contentScrollX(50)
							break;
						case 'right':
							scrollBar.contentScrollX(-50)
							break;
					}
				}
				if(delta<0){
					//console.log("scrollDown");
					switch(scrollBar.scrollStart.x){
						case 'left':
							scrollBar.contentScrollX(-50)
							break;
						case 'right':
							scrollBar.contentScrollX(50)
							break;
					}
				}
			}
		});







		scrollBar.touchScroll={
			isStart:false,
			touchTarget:'content',
			start:function(isStart){
				if(isStart){
					scrollBar.touchScroll.isStart=true;
					scrollBar.$scrollWindow.addClass('user-select-none');
				}else{
					scrollBar.touchScroll.isStart=false;
					scrollBar.$scrollWindow.removeClass('user-select-none');
				}
			},
			postion:{
				y:0
			}
		}
		scrollBar.$scrollWindow.on('touchstart',function(e){
			if(scrollBar.touchDrag){
				e.preventDefault();
				var touchePosition=e.originalEvent.targetTouches[0];
				scrollBar.touchScroll.touchTarget='content';
				scrollBar.touchScroll.postion.x=touchePosition.pageX;
				scrollBar.touchScroll.postion.y=touchePosition.pageY;
				scrollBar.touchScroll.start(true);
			}
		});
		scrollBar.$scrollBarX.on('touchstart',function(e){
			if(scrollBar.touchDrag){
				e.preventDefault();
				e.stopPropagation();
				var touchePosition=e.originalEvent.targetTouches[0];
				scrollBar.touchScroll.touchTarget='scrollBarX';
				scrollBar.touchScroll.postion.x=touchePosition.pageX;
				scrollBar.touchScroll.postion.y=touchePosition.pageY;
				scrollBar.touchScroll.start(true);
			}
		});
		scrollBar.$scrollBarY.on('touchstart',function(e){
			if(scrollBar.touchDrag){
				e.preventDefault();
				e.stopPropagation();
				var touchePosition=e.originalEvent.targetTouches[0];
				scrollBar.touchScroll.touchTarget='scrollBarY';
				scrollBar.touchScroll.postion.x=touchePosition.pageX;
				scrollBar.touchScroll.postion.y=touchePosition.pageY;
				scrollBar.touchScroll.start(true);
			}
		});
		scrollBar.$scrollWindow.on('touchmove',function(e){
			if(scrollBar.touchScroll.isStart){
				var touchePosition=e.originalEvent.targetTouches[0];
				var moveLength={
					x:0,
					y:0
				};
				switch(scrollBar.scrollStart.x){
					case 'left':
						moveLength.x=scrollBar.touchScroll.postion.x-touchePosition.pageX;
						break;
					case 'right':
						moveLength.x=touchePosition.pageX-scrollBar.touchScroll.postion.x;
						break;
				}
				switch(scrollBar.scrollStart.y){
					case 'top':
						moveLength.y=scrollBar.touchScroll.postion.y-touchePosition.pageY;
						break;
					case 'bottom':
						moveLength.y=touchePosition.pageY-scrollBar.touchScroll.postion.y;
						break;
				}
				switch(scrollBar.touchScroll.touchTarget){
					case 'content':
						scrollBar.contentScrollX(-moveLength.x);
						scrollBar.contentScrollY(-moveLength.y);
						break;
					case 'scrollBarX':
						scrollBar.contentScrollX(moveLength.x,true);
						break;
					case 'scrollBarY':
						scrollBar.contentScrollY(moveLength.y,true);
						break;
				}
				scrollBar.touchScroll.postion.x=touchePosition.pageX;
				scrollBar.touchScroll.postion.y=touchePosition.pageY;
			}
		});
		scrollBar.$scrollWindow.on('touchend touchout',function(e){
			scrollBar.touchScroll.start(false);
		});
	}
	window.ScrollBar=ScrollBar;
	return ScrollBar;
})
